﻿-- brotherhobbes@gmail.com

assert( oRA, "oRA not found!")

------------------------------
--      Are you local?      --
------------------------------

local L = AceLibrary("AceLocale-2.2"):new("oRALDifficulty")

local dungeonDifficulties = {
	["Normal"] = 1,
	["Heroic"] = 2,
	["Epic"] = 3,
}

----------------------------
--      Localization      --
----------------------------

L:RegisterTranslations("enUS", function() return {
	["Leader/Difficulty"] = true,
	["Difficulty"] = true,
	["Options for dungeon difficulty."] = true,
	["Set the dungeon difficulty."] = true,
	["Normal"] = true,
	["Heroic"] = true,
	["Epic"] = true,
    ["<difficulty>"] = true,	
} end )
L:RegisterTranslations("zhCN", function() return {
	["Leader/Difficulty"] = "\233\128\137\230\139\169\233\154\190\229\186\166",
	["Difficulty"] = "\233\154\190\229\186\166",
	["Options for dungeon difficulty."] = "\229\137\175\230\156\172\233\154\190\229\186\166\233\128\137\233\161\185",
	["Set the dungeon difficulty."] = "\232\174\190\231\189\174\229\137\175\230\156\172\233\154\190\229\186\166",
	["Normal"] = "\230\153\174\233\128\154",
	["Heroic"] = "\232\139\177\233\155\132",
	["Epic"] = "\229\143\178\232\175\151",
    ["<difficulty>"] = "<\233\154\190\229\186\166>",
} end )
L:RegisterTranslations("zhTW", function() return {
	["Leader/Difficulty"] = "\233\129\184\230\147\135\233\155\163\229\186\166",
	["Difficulty"] = "\233\155\163\229\186\166",
	["Options for dungeon difficulty."] = "\229\137\175\230\156\172\233\155\163\229\186\166\233\129\184\233\160\133",
	["Set the dungeon difficulty."] = "\232\168\173\231\189\174\229\137\175\230\156\172\233\155\163\229\186\166",
	["Normal"] = "\230\153\174\233\128\154",
	["Heroic"] = "\232\139\177\233\155\132",
	["Epic"] = "\229\143\178\232\169\169",
    ["<difficulty>"] = "<\233\155\163\229\186\166>",
} end )
----------------------------------
--      Module Declaration      --
----------------------------------

local mod = oRA:NewModule("LeaderDifficulty")
mod.defaults = {
	difficulty = L["Heroic"],
}
mod.leader = true
mod.name = L["Leader/Difficulty"]
mod.consoleCmd = "difficulty"
mod.consoleOptions = {
	type = "text",
	name = L["Difficulty"], desc = L["Set the dungeon difficulty."],
	disabled = function() return not oRA:IsActive() end,
	get = function() return mod.db.profile.difficulty end,
	set = function(v) 
		mod.db.profile.difficulty = v
		mod:SetDungeonDifficulty()
	end,
	validate = { L["Normal"], L["Heroic"], L["Epic"] },
	usage = L["<difficulty>"],
}

------------------------------
--      Initialization      --
------------------------------

function mod:OnEnable()
	self:SetDungeonDifficulty()
end

----------------------
-- Command handlers --
----------------------

function mod:SetDungeonDifficulty()
	if not IsRaidLeader() then return end

	local difficulty = self.db.profile.difficulty

	if not (difficulty and L:HasReverseTranslation( difficulty ) and dungeonDifficulties[L:GetReverseTranslation(difficulty)]) then
		difficulty = self.defaults.difficulty
	end
	difficulty = dungeonDifficulties[L:GetReverseTranslation(difficulty)]	

	self:ScheduleEvent("oradungeondifficulty", SetDungeonDifficulty, 3, difficulty)
end
